/**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 */
define(['N/ui/serverWidget', 'N/ui/dialog', 'N/record', 'N/search'], function (ui, dialog, record, search) {
    function onRequest(context) {
        try {
            var form = ui.createForm({
                title: '工作单发料'
            });
            form.clientScriptModulePath = './cs_wosend';
            form.addSubmitButton({
                label: '提交'
            });
            form.addResetButton({
                label: '重置'
            });
            //工作单信息
            form.addFieldGroup({
                id: 'fieldgroupid1',
                label: '工作单信息'
            });
            var woNum = form.addField({
                id: 'custpage_wo_num',
                type: ui.FieldType.SELECT,
                label: '工单号',
                source: record.Type.WORK_ORDER,
                container: 'fieldgroupid1'
            });
            var assembly = form.addField({
                id: 'custpage_assembly',
                type: ui.FieldType.SELECT,
                label: '装配件',
                source: record.Type.ASSEMBLY_ITEM,
                container: 'fieldgroupid1'
            });
            var subsidiary = form.addField({
                id: 'custpage_subsidiary',
                type: ui.FieldType.SELECT,
                label: '子公司',
                source: record.Type.SUBSIDIARY,
                container: 'fieldgroupid1'
            });
            var woProcessNum = form.addField({
                id: 'custpage_woprocessseq',
                type: ui.FieldType.TEXT,
                label: '工序号',
                container: 'fieldgroupid1'
            });
            var woProcessName = form.addField({
                id: 'custpage_woprocessname',
                type: ui.FieldType.TEXT,
                label: '工序名称',
                container: 'fieldgroupid1'
            });
            var woProcessType = form.addField({
                id: 'custpage_woprocesstype',
                type: ui.FieldType.SELECT,
                label: '工序类型',
                source: 'customlist_processtype',
                container: 'fieldgroupid1'
            });
            var receiptLocation = form.addField({
                id: 'custpage_receiptlocation',
                type: ui.FieldType.SELECT,
                label: '收货地点',
                source: record.Type.LOCATION,
                container: 'fieldgroupid1'
            });
            var maxprocessnumber = form.addField({
                id: 'custpage_maxprocessnumber',
                type: ui.FieldType.INTEGER,
                label: '最大工序序号',
                container: 'fieldgroupid1'
            });
            woNum.updateDisplayType({
                displayType: ui.FieldDisplayType.INLINE
            });
            assembly.updateDisplayType({
                displayType: ui.FieldDisplayType.INLINE
            });
            subsidiary.updateDisplayType({
                displayType: ui.FieldDisplayType.INLINE
            });
            woProcessName.updateDisplayType({
                displayType: ui.FieldDisplayType.INLINE
            });
            woProcessType.updateDisplayType({
                displayType: ui.FieldDisplayType.INLINE
            });
            receiptLocation.updateDisplayType({
                displayType: ui.FieldDisplayType.INLINE
            });
            maxprocessnumber.updateDisplayType({
                displayType: ui.FieldDisplayType.INLINE
            });
            woProcessNum.isMandatory = true;
            //工序对应非费用组件列表
            var itemsSublist = form.addSublist({
                id: 'custpage_sublist_items',
                type: ui.SublistType.INLINEEDITOR,
                label: '工序对应组件列表'
            });
            var custpage_item = itemsSublist.addField({
                id: 'custpage_item',
                type: ui.FieldType.SELECT,
                label: '货品',
                source: record.Type.KIT_ITEM
            });
            var custpage_from_location = itemsSublist.addField({
                id: 'custpage_from_location',
                type: ui.FieldType.SELECT,
                label: '起始地点',
                source: record.Type.LOCATION
            });
            var custpage_from_bin = itemsSublist.addField({
                id: 'custpage_from_bin',
                type: ui.FieldType.SELECT,
                label: '起始库位'
            });
            var custpage_onhand_quantity = itemsSublist.addField({
                id: 'custpage_onhand_quantity',
                type: ui.FieldType.FLOAT,
                label: '现有量'
            });
            var custpage_available_quantity = itemsSublist.addField({
                id: 'custpage_available_quantity',
                type: ui.FieldType.FLOAT,
                label: '可用量'
            });
            var custpage_quantity = itemsSublist.addField({
                id: 'custpage_quantity',
                type: ui.FieldType.FLOAT,
                label: '数量'
            });
            var custpage_transfer_price = itemsSublist.addField({
                id: 'custpage_transfer_price',
                type: ui.FieldType.TEXT,
                label: '转让价格'
            });
            var custpage_receipt_bin = itemsSublist.addField({
                id: 'custpage_receipt_bin',
                type: ui.FieldType.SELECT,
                label: '收货库位',
                source: record.Type.BIN
            });
            var custpage_receipt_bin_available = itemsSublist.addField({
                id: 'custpage_receipt_bin_available',
                type: ui.FieldType.FLOAT,
                label: '收货库位可用量'
            });
            /*custpage_item.isMandatory = true;
            custpage_from_location.isMandatory = true;
            custpage_onhand_quantity.isMandatory = true;
            custpage_available_quantity.isMandatory = true;
            custpage_quantity.isMandatory = true;
            custpage_transfer_price.isMandatory = true;
            custpage_receipt_bin.isMandatory = true;
            custpage_receipt_bin_available.isMandatory = true;*/
            //log.debug(context.request.method+'请求', context);
            woNum.defaultValue = JSON.parse(context.request.parameters.custpage_wo_num);
            context.response.writePage(form);
        } catch (e) {
            log.debug('e', JSON.stringify(e));
        }
    }

    return {
        onRequest: onRequest
    };
});